package leetcode.bitarithmetic;

import java.util.stream.IntStream;

public class MissingNumber268 {
    //二进制
    class Solution1 {
        public int missingNumber(int[] nums) {
            int ans = 0;
            for (int i = 0; i <= nums.length ; ++i) {
                ans ^= i;
            }
            for (int num : nums) {
                ans ^= num;
            }
            return ans;
        }
    }

    //高斯求和
    class Solution2 {
        public int missingNumber(int[] nums) {
            return ((0 + 1) * nums.length + 1) / 2 - IntStream.of(nums).sum();
        }
    }
}
